package com.only4play.web.resource;

import com.only4play.common.model.GeneralResponse;
import com.only4play.dto.PersonAuthenticateDto;
import com.only4play.dto.PersonRegisterDto;
import com.only4play.service.UserPersonalAccountService;
import com.only4play.vo.UserPersonAccountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

/**
 * @author liyuncong
 * @version 1.0
 * @file UserPersonResources
 * @brief UserPersonResources
 * @details UserPersonResources
 * @date 2023-12-12
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2023-12-12  liyuncong          Created
 */
@RestController
@RequestMapping(
    value = "/api/v1/people",
    produces = MediaType.APPLICATION_JSON_VALUE
)
public class UserPersonResources {
    @Autowired
    private UserPersonalAccountService userPersonalAccountService;

    /**
     * 用户认证
     *
     * @param authenticateDto 用户数据
     * @return 认证结果
     */
    @PostMapping("/authenticate")
    public GeneralResponse<Boolean> authenticate(
        @Valid @NotNull @RequestBody PersonAuthenticateDto authenticateDto
    ) {
        return GeneralResponse.of(userPersonalAccountService.authenticate(
            authenticateDto.getLoginUsername(), authenticateDto.getLoginPassword()));
    }

    /**
     * 根据登录名查询用户数据
     *
     * @param loginUsername 登录名
     * @return 用户数据
     */
    @GetMapping("/queryByLoginUsername")
    public GeneralResponse<UserPersonAccountVo> queryByLoginUsername(
        @Valid @NotNull @RequestParam("loginUsername") String loginUsername
    ) {
        return GeneralResponse.of(userPersonalAccountService.queryByLoginUsername(loginUsername));
    }

}
